home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / query.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  4KB  |  139 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '0.2'
  5. __title__ = 'Model Query Utility'
  6. __mod__ = 'hp-query'
  7. __doc__ = 'Query a printer model for static model information. Designed to be called from other processes.'
  8. import sys
  9. from base.g import *
  10. from base import device, models, module
  11.  
  12. try:
  13.     mod = module.Module(__mod__, __title__, __version__, __doc__, None, (NON_INTERACTIVE_MODE,), quiet = True)
  14.     mod.setUsage(0, extra_options = [
  15.         ('Specify model by device URI:', '-d<device_uri> or --device=<device_uri>', 'option', False),
  16.         ('Specify normalized model name:', '-m<model_name> or --model=<model_name> (normalized models.dat format)', 'option', False),
  17.         ('Specify raw model name:', '-r<model_name> or --raw=<model_name> (raw model name from MDL: field of device ID)', 'option', False),
  18.         ('Specify key to query:', '-k<key> or --key=<key> (or, use -a/--all to return all keys)', 'option', False),
  19.         ('Query all keys:', '-a or --all (default separator is a LF)', 'option', False),
  20.         ('Specify the separator when multiple keys are queried:', "-s<sep> --sep=<sep> (character or 'tab', 'newline', 'cr', 'lf', 'crlf')(only valid when used with -a/--all)", 'option', False),
  21.         ('Suppress trailing linefeed:', '-x', 'option', False)], see_also_list = [
  22.         'hp-info'])
  23.     (opts, device_uri, printer_name, mode, ui_toolkit, lang) = mod.parseStdOpts('m:k:as:d:r:x', [
  24.         'model=',
  25.         'key=',
  26.         'sep=',
  27.         'all',
  28.         'device=',
  29.         'raw='], handle_device_printer = False)
  30.     norm_model = None
  31.     raw_model = None
  32.     device_uri = None
  33.     key = None
  34.     all_keys = False
  35.     sep = 'lf'
  36.     suppress_trailing_linefeed = False
  37.     for o, a in opts:
  38.         if o in ('-m', '--model'):
  39.             norm_model = a
  40.             continue
  41.         if o in ('-d', '--model'):
  42.             device_uri = a
  43.             continue
  44.         if o in ('-k', '--key'):
  45.             key = a
  46.             all_keys = False
  47.             continue
  48.         if o in ('-a', '--all'):
  49.             all_keys = True
  50.             key = None
  51.             continue
  52.         if o in ('-r', '--raw'):
  53.             raw_model = a
  54.             continue
  55.         if o in ('-s', '--sep'):
  56.             sep = a
  57.             continue
  58.         if o == '-x':
  59.             suppress_trailing_linefeed = True
  60.             continue
  61.     
  62.     if not device_uri or norm_model:
  63.         if (device_uri or raw_model or norm_model) and raw_model:
  64.             log.stderr('error: You may only specify one of -d, -m, or -r.')
  65.             sys.exit(1)
  66.         
  67.     if not device_uri and not norm_model and not raw_model:
  68.         log.stderr('error: You must specify one of -d, -m, or -r.')
  69.         sys.exit(1)
  70.     
  71.     if device_uri:
  72.         
  73.         try:
  74.             (back_end, is_hp, bus, norm_model, serial, dev_file, host, zc, port) = device.parseDeviceURI(device_uri)
  75.         except Error:
  76.             log.stderr('error: Invalid device URI: %s' % device_uri)
  77.             sys.exit(1)
  78.         except:
  79.             None<EXCEPTION MATCH>Error
  80.         
  81.  
  82.     None<EXCEPTION MATCH>Error
  83.     if raw_model:
  84.         norm_model = models.normalizeModelName(raw_model).lower()
  85.     
  86.     if not norm_model:
  87.         log.stderr('error: Invalid model name.')
  88.         sys.exit(1)
  89.     
  90.     s = sep.lower()
  91.     if s in ('lf', 'newline'):
  92.         sep = '\n'
  93.     elif s == 'cr':
  94.         sep = '\r'
  95.     elif s == 'crlf':
  96.         sep = '\r\n'
  97.     elif s == 'tab':
  98.         sep = '\t'
  99.     elif s == '=':
  100.         log.stderr("error: Separator must not be '='.")
  101.         sys.exit(1)
  102.     
  103.     data = device.queryModelByModel(norm_model)
  104.     if not data:
  105.         log.stderr("error: Model name '%s' not found." % norm_model)
  106.         sys.exit(1)
  107.     
  108.     output = ''
  109.     if all_keys:
  110.         kk = data.keys()
  111.         kk.sort()
  112.         for k in kk:
  113.             if not output:
  114.                 output = '%s=%s' % (k, data[k])
  115.                 continue
  116.             output = sep.join([
  117.                 output,
  118.                 '%s=%s' % (k, data[k])])
  119.         
  120.     elif key:
  121.         
  122.         try:
  123.             data[key]
  124.         except KeyError:
  125.             log.stderr("error: Key '%s' not found." % key)
  126.             sys.exit(1)
  127.  
  128.         output = '%s=%s' % (key, data[key])
  129.     else:
  130.         log.stderr('error: Must specify key with -k/--key or specify -a/--all.')
  131.         sys.exit(1)
  132.     if suppress_trailing_linefeed:
  133.         print output,
  134.     else:
  135.         print output
  136. except KeyboardInterrupt:
  137.     pass
  138.  
  139.